package com.example.xpagedemoproject.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.example.xpagedemoproject1.R;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xpage.base.XPageFragment;
import com.xuexiang.xpage.utils.TitleBar;
import com.xuexiang.xrouter.annotation.AutoWired;
import com.xuexiang.xrouter.launcher.XRouter;

import butterknife.BindView;

@Page(name = TestFragment.PAGE_NAME,extra = 123)
public class TestFragment extends XPageFragment {
    public static final String PAGE_NAME = "测试页面";
    public static final String KEY_TOP_BACK_NAME = "key_top_back_name";

    @BindView(R.id.tv_content)
    TextView tvContent;

    @AutoWired(name = DataReceiveFragment.KEY_IS_NEED_BACK)
    boolean isNeedBack;
    @AutoWired(name = KEY_TOP_BACK_NAME)
    String popBackName;

    @Override
    protected TitleBar initTitleBar() {
        return super.initTitleBar().setLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isNeedBack) {
                    Intent intent = new Intent();
                    intent.putExtra(DataReceiveFragment.KEY_BACK_DATA,"==[返回的数据]==");
                    setFragmentResult(500,intent);
                }
                popToBack(popBackName,null);
            }
        });
    }

    @Override
    protected void initArgs() {
        XRouter.getInstance().inject(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_test;
    }

    @Override
    protected void initViews() {
        tvContent.setText(getPageName());
    }

    @Override
    protected void initListeners() {

    }
}
